package xio.ccf_201604;

import java.util.Scanner;
import java.util.Stack;

/**
 * ccf 201604-3 路径解析 不知道啥问题。。。只有60分。。。
 * Created by ywb47 on 2017/9/29.
 */
public class PathAnalysis {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt(); //测试数目
        sc.nextLine();
        String pwd = sc.nextLine(); //当前目录
        String[] src = new String[count];
        for (int i = 0; i < count; i++) {
            src[i] = sc.nextLine();
        }
        Stack<String> pwdStack = new Stack<>();
        String[] pwdDir = pwd.split("/");


        for (String s : src) {
            //初始化当前目录
            pwdStack.removeAllElements();
            for (String r : pwdDir) {
                if (!r.isEmpty()) {
                    pwdStack.push(r);
                }
            }

            String[] result = s.split("/");
            if (result.length == 0){
                System.out.println("/");
                continue;
            }
            int startIndex = 0;
            String firstChar = result[0];
            if (!pwdStack.isEmpty()){
                startIndex = 1;
                if (firstChar.equals("..")){
                    pwdStack.pop();
                }else if (firstChar.isEmpty()){
                    pwdStack.removeAllElements();
                } else if (!firstChar.equals(".")){
                    pwdStack.removeAllElements();
                    pwdStack.push(result[0]);
                }
            }

            for (int i = startIndex; i < result.length; i++) {
                String str = result[i];
                if (str.isEmpty() || str.equals(".")){
                    continue;
                }
                if (str.equals("..")){
                    if (!pwdStack.empty()) {
                        pwdStack.pop();
                    }
                    continue;
                }
                pwdStack.push(str);
            }
            StringBuilder sb = new StringBuilder();
            if (pwdStack.isEmpty()){
                sb.append("/");
            }else {
                for (String s1 : pwdStack) {
                    sb.append("/").append(s1);
                }
            }
            System.out.println(sb.toString());
        }
    }
}
